﻿using OneWeb.DbContexts;
using OneWeb.Repository;
using OneWeb.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace OneWeb.Controllers
{
    /// <summary>
    /// 首页
    /// </summary>
    [RoutePrefix("home")]
    public class HomeController : Controller
    {
        ContentRepository contentRepository = new ContentRepository();

        [Route("index")]
        public ActionResult Index(int? id)
        {
            HomePageViewModel viewModel = new HomePageViewModel();
            if (id==null)
            {
                viewModel.CurrentContent = contentRepository.GetToday();
                viewModel.PreviousContent = contentRepository.GetPrevious();
                viewModel.NextContent = contentRepository.GetNext();
            }
            else
            {
                viewModel.CurrentContent = contentRepository.GetToday((int)id);
                viewModel.PreviousContent = contentRepository.GetPrevious((int)id);
                viewModel.NextContent = contentRepository.GetNext((int)id);
            }
            
            return View(viewModel);
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
         
    }
}